package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.MatRepair;
import com.indusfo.spc.pojo.MatRepair;
import com.indusfo.spc.pojo.MatVer;
import com.indusfo.spc.service.MatRepairService;
import com.indusfo.spc.service.MatRepairService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liub
 * @Date 2019/11/25 8:38
 * @Version 1.0
 */

@Controller
@RequestMapping(value = "/service/matRepair")
public class MatRepairController {


    @Autowired
    private MatRepairService matRepairService;

    /**
     * 查询
     */
    @RequestMapping(value = "/queryMatRepair")
    @ResponseBody
    public JSONObject queryMatRepair(MatRepair matRepair) {
        JSONObject json = matRepairService.queryMatRepair(matRepair);
        return json;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/insertMatRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject insertMatRepair(MatRepair matRepair) {
        JSONObject json = matRepairService.insertMatRepair(matRepair);
        return json;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/updateMatRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject updateMatRepair(MatRepair matRepair) {
        JSONObject json = matRepairService.updateMatRepair(matRepair);
        return json;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/deleteMatRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteMatRepair(@RequestParam("matRepairIds") List<Integer> matRepairIds, Integer dataState) {
        dataState = 2;
        JSONObject json = matRepairService.deleteMatRepair(matRepairIds, dataState);
        return json;
    }

    /**
     * 级联删除维修流程关联的工序、维修采集参数
     */
    @RequestMapping(value = "/deleteCascadeMatRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject deleteCascadeMatRepair(@RequestParam("matRepairIds") List<Integer> matRepairIds, Integer dataState) {
        dataState = 2;
        try {
            return matRepairService.deleteCascadeMatRepair(matRepairIds, dataState);
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(JSONObject.ERROR, e.getMessage(), null);
        }
    }

    /**
     * 启停
     */
    @RequestMapping(value = "/definedMatRepair", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject definedMatRepair(@RequestParam("matRepairIds") List<Integer> matRepairIds, Integer dataState) {
        JSONObject json = matRepairService.deleteMatRepair(matRepairIds, dataState);
        return json;
    }

    /**
     * @Author 熊冰 保存维修流程 工序
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatRepairFlow", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatRepairFlow(@RequestBody MatRepair matRepair) {
        JSONObject json = matRepairService.saveMatRepairFlow(matRepair);
        return json;
    }

    /**
     * @Author 熊冰 保存维修流程 采集项目
     * @Date 2019/11/23 10:34
     */
    @RequestMapping(value = "/saveMatRepairDete", method = RequestMethod.POST)
    @ResponseBody
    public JSONObject saveMatRepairDete(@RequestBody MatRepair matRepair) {
        JSONObject json = matRepairService.saveMatRepairDete(matRepair);
        return json;
    }
}
